package cp3;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloWorldServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //
        System.out.println("处理get请求");
        // 第一种处理乱码:
        resp.setHeader("Content-Type","text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8"); //
        // 第二种处理乱码:
        resp.setContentType("text/html;charset=utf-8");
        // 获取http的输出对象 如果需要设置输出编码 必须放在之前
        PrintWriter out = resp.getWriter();
        //输出到浏览器
        out.println("<h1>处理get请求,hello world</h1>");
    }
}
